import pymysql
import sys

userName=str(sys.argv[1])

sqlCmd='select * from table where user="'+userName+'"'


print("需要查询的用户名为",userName)
print("查询语句为",sqlCmd)

coon = pymysql.connect(
    host = '127.0.0.1',user = 'root',passwd = '123456',
    port = 3306,db = 'mydb',charset = 'utf8'
    #port必须写int类型
    #charset必须写utf8，不能写utf-8
)
cur = coon.cursor()  #建立游标
cur.execute(sqlCmd)  #查询数据
res = cur.fetchall()    #获取结果
print("查询结果",res)
cur.close()     #关闭游标
coon.close()    #关闭连接